import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/23 22:54
 * @description 排序 + 贪心
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 2, 3, 4, 5};
        solution.rearrangeArray(nums);
    }

    public int[] rearrangeArray(int[] nums) {
        Arrays.sort(nums);
        int n = nums.length, left = 0, right = n - 1;
        int[] ans = new int[n];
        boolean flag = true;
        for (int i = 0; i < n; i++) {
            ans[i] = flag ? nums[left++] : nums[right--];
            flag = !flag;
        }
        return ans;
    }
}
